package com.ylbh.modules.goods.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.exception.NormalException;
import com.ylbh.common.pojo.goods.dto.GoodsDTO;
import com.ylbh.common.pojo.goods.dto.GoodsDetailsDTO;
import com.ylbh.common.pojo.goods.dto.GoodsListDTO;
import com.ylbh.common.pojo.goods.dto.SpecIficationDTO;
import com.ylbh.common.pojo.goods.vo.GoodsDetailsVO;
import com.ylbh.common.pojo.goods.vo.ManufactorVO;
import com.ylbh.common.pojo.goods.vo.SpecIficationVO;
import com.ylbh.common.utils.*;
import com.ylbh.modules.goods.service.GoodsSpecService;
import com.ylbh.modules.goods.service.ShoppingGoodsService;
import com.ylbh.modules.goods.service.SupplierGoodsService;
import com.ylbh.modules.sys.controller.AbstractController;
import com.ylbh.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * @author mgh
 */
@RestController
@RequestMapping("goods/supplier")
public class SupplierGoodsController extends AbstractController {
    @Autowired
    private SupplierGoodsService supplierGoodsService;
    @Autowired
    private ShoppingGoodsService shoppingGoodsService;

    @Value("${url.shoppingMainImage}")
    private String uploadHost;

    @ApiOperation("运营商商品信息列表")
    @RequestMapping("queryGoodsList")
    @RequiresPermissions("goods:supplier:queryGoodsList")
    public CommonResult<PageUtils> queryGoodsList(GoodsListDTO goodsListDTO){
        goodsListDTO.setGoodsManagerId(getUserId().intValue());
        PageUtils utils = supplierGoodsService.queryGoodsList(goodsListDTO);

        return Ref.ok(utils);
    }

    @ApiOperation("运营商厂家列表")
    @RequestMapping("queryManufactorList")
    @RequiresPermissions("goods:supplier:queryGoodsList")
    public CommonResult<List<ManufactorVO>> queryManufactorList(){
        List<ManufactorVO> list = supplierGoodsService.queryManufactorList();
        return Ref.ok(list);
    }

    @ApiOperation("运营商商品导出")
    @RequestMapping("goodsExcel")
    public CommonResult goodsExcel(HttpServletResponse response, HttpServletRequest request) throws NormalException {
        shoppingGoodsService.goodsExcel(response, request);
        return Ref.ok();
    }

    @ApiOperation("供应商类型")
    @RequestMapping("queryRoleType")
    public CommonResult<Integer> queryRoleType() {
        Integer type = supplierGoodsService.queryRoleType(getUserId());
        return Ref.ok(type);
    }

    @SysLog("对供应商商品进行上下架操作")
    @ApiOperation("对供应商商品进行上下架操作")
    @RequestMapping("queryRoleType/{id}/{type}")
    public CommonResult<Void> modifyGoodsStatusById(@PathVariable String id, @PathVariable Integer type) {
        supplierGoodsService.modifyGoodsStatusById(id, type, getUserId());
        return Ref.ok();
    }

    @ApiOperation("供应商列表")
    @GetMapping("queryAllRole")
    public CommonResult queryAllRole() {
        List<SysUserEntity> list = supplierGoodsService.queryAllRole();
        return Ref.ok(list);
    }
}
